package com.linxz.ui.dialogs;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.linxz.ui.R;

/**
 * @author Linxz
 * 创建日期：2019年10月19日 22:53
 * version：v4.5.4
 * 描述：图片上传Dialog
 */
public class ImageUploadDialog {

    private Context context;
    private Dialog dialog;
    private TextView message;
    private int imageCount;


    public ImageUploadDialog(Context context, int imageCount) {
        this.context = context;
        this.imageCount = imageCount;
        init();
    }

    private void init() {
        dialog = new Dialog(context, R.style.ui_default_dialog_style);
        @SuppressLint("InflateParams") View contentView = LayoutInflater.from(context).inflate(R.layout.ui_dialog_upload_images, null);
        message = contentView.findViewById(R.id.message);
        updateProgress(0);
        dialog.setContentView(contentView);
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
        Window window = dialog.getWindow();
        if (window != null) {
            window.getAttributes().gravity = Gravity.CENTER;
            WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
            lp.dimAmount = 0.2f;
            dialog.getWindow().setAttributes(lp);
        }
    }

    public void show() {
        if (dialog != null) {
            dialog.show();
        }
    }

    public void dismiss() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    @SuppressLint("SetTextI18n")
    public void updateProgress(int count) {
        message.setText(count + "/" + imageCount + "张图片...");
    }

}
